/*
 * @Description: Map Student
 * @Author: rendc
 * @Date: 2025-08-14 10:26:39
 * @LastEditors: rendc
 * @LastEditTime: 2025-08-14 11:09:26
 */

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class TestMapStudent {

  public static void main(String[] args) {
    // 创建一个HashMap集合
    Map<Student, String> map = new HashMap<>();
    // 添加元素 给指定的key赋value值
    map.put(new Student("zs", 18), "2025001");
    map.put(new Student("ls", 19), "2025002");
    map.put(new Student("ww", 22), "2025003");
    map.put(new Student("zs", 18), "2025001");
    // 使用map.put时 要先判断这里有没值
    System.out.println("map.size():" + map.size());
    System.out.println("map:" + map);
    // 遍历 方法1
    Set<Student> set = map.keySet();
    System.out.println(set);
    for (Student s : set) {
      // map.set
      System.out.println(map.get(s));
    }
    // 遍历 方法2
    Collection<String> coll = map.values();
    for (String s : coll) {
      System.out.println(s);
    }

    // 遍历 方法3 entrySet()
    Set<Map.Entry<Student, String>> entrys = map.entrySet();
    for (Entry<Student, String> entry : entrys) {
      // 遍历的同时修改值
      // entry.setValue("hi");
      System.out.println(entry.getKey() + "-" + entry.getValue());
    }
  }

}